﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pg.BioMedics.SDR.Services.Linq
{
    internal class EqualityComparer<T> : IEqualityComparer<T>
    {
        public Func<T, T, bool> Comparer { get; internal set; }
        public Func<T, int> Hasher { get; internal set; }

        bool IEqualityComparer<T>.Equals(T x, T y)
        {
            return this.Comparer(x, y);
        }

        int IEqualityComparer<T>.GetHashCode(T obj)
        {
            // No hashing capabilities. Default to Equals(x, y).
            if (this.Hasher == null)
                return 0;

            return this.Hasher(obj);
        }
    }
}
